<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>setPrototypeOf()</title>
</head>
<body>
  <script>
    // setPrototypeOf()方法主要用来拦截Object.setPrototypeOf()
    var handler = {
      setPrototypeOf(target, proto) {
        throw new Error('Changing the prototype is forbidden')
      }
    }
    var proto = {}
    var target = function () {};
    var proxy = new Proxy(target, handler);
    Object.setPrototypeOf(proxy, proto)
    //Changing the prototype is forbidden
    // 注意，该方法只能返回布尔值，否则会被转换为布尔值，另外
    // 如果目标对象不可扩展(non-extensible), setPrototypeOf()方法不得改变目标对象的原型
  </script>
</body>
</html>